package controllers

/**
* @author: 李显赫
* @create: 2022-11-2 20:22:23
**/

import (
	"encoding/json"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	"myc/models"
)

type AuthController struct {
	beego.Controller
}

// 判断是否为作者
func (this *AuthController) Post() {

	u := &models.Panel{}

	json.Unmarshal(this.Ctx.Input.RequestBody, u)

	beego.Info(u.Id, u.Pwd)

	mystruct := &JSONStruct{}

	// 创建orm对象
	o := orm.NewOrm()

	// 使用主键查询
	// 使用Username字段查询
	err := o.Read(u, "pwd", "id")

	if err != nil {
		// 打印错误日志
		beego.Info(err)
		mystruct.Code = 500
		mystruct.Msg = "认证失败"
	} else {
		mystruct.Code = 200
		mystruct.Msg = "认证成功"
	}

	this.Data["json"] = mystruct
	this.ServeJSON()
}